package cst.a931xmc.yuejian20.Fragment.Me;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cst.a931xmc.yuejian20.Adapter.MyOrderAdapter;
import cst.a931xmc.yuejian20.Bean.ActivityOrderBean;
import cst.a931xmc.yuejian20.Listener.Listener;
import cst.a931xmc.yuejian20.Model.ActivityModel;
import cst.a931xmc.yuejian20.R;

public class MyAorderFragment extends Fragment {
    private RecyclerView recyclerView;
    private MyOrderAdapter adapter;
    private RecyclerView.LayoutManager layoutManager;
    private Listener<List<ActivityOrderBean>> listener;
    private ActivityModel model;
    private int user_id;
    SharedPreferences sp;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_myaorder,container,false);
        initViews(view);
        initData();
        model=new ActivityModel();
        model.getOrderList(user_id, listener);
        return view;
    }

    public void initViews(View view){
        recyclerView = view.findViewById(R.id.rv_myaorder);
        adapter = new MyOrderAdapter(getActivity());
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        sp = this.getActivity().getSharedPreferences("user_id", Context.MODE_PRIVATE);
        user_id = sp.getInt("user_id",0);
    }

    public void initData(){
        listener = new Listener<List<ActivityOrderBean>>() {
            @Override
            public void onResponse(List<ActivityOrderBean> list) {
                recyclerView.setAdapter(adapter);
                adapter.setAOrderList(list);
            }

            @Override
            public void onFail(String message) {

            }
        };
    }
}
